const app = getApp();  
let ajaxTime = 0;
const request = (params) => {
  wx.showLoading({
    title: '加载中...',
    mask: true,
  });
  const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
  return new Promise((resolve, reject) => {
    ajaxTime++;
    wx.request({
      ...params,
      url: baseUrl + params.url,
      success: (result) => {
        resolve(result.data.message)
      },
      fail: (res) => {
        reject(res)
      },
      complete: (res) => { 
        ajaxTime -- ;
        if(ajaxTime === 0){
          wx.hideLoading();

        }
      },
    })
  })
}
export { request }
